<template>
  <div>
    <article class="innerPage bookList">
      <header class="breadcrumb">
        <x-breadcrumb :path="$route.path" :title="$route.meta.breadcrumb" :startIndex="$route.meta.startIndex">
        </x-breadcrumb>
      </header>
      <section>
        <div style="height:20px;"></div>

        <vmform class="act-form" @btn_submit="btn_submit" type="chang" :fromData="fromData" @cancel="$router.back()"></vmform>
      </section>
    </article>
  </div>
</template>

<script>
import vmform from "../components/form.vue";
export default {
  components: {
    vmform,
  },
  props: {},
  data() {
    return {
      fromData: {
        name: '',
        link: '',
        img: '',
        big_type_id: '',
        sort: '',
        skip_way: '',
        intro: '',
        id: '',
      },
    };
  },
  computed: {},
  watch: {},
  activated() {
    if (this.$route.query?.action != 'refresh' ) {

      this.fromData = this.$options.data().fromData;
      this.getinfo();
    }
    this.setPageTabs();


  },
  mounted() { },
  methods: {
    // 获取详情
    async getinfo() {
      try {
        let res = await this.request({
          url: "/admin/banner/detail",
          method: "get",
          loading: true,
          data: {
            id: this.$route.query.id,
          },
        });
        if (res) {
          this.fromData = {
            name: res.content.name,
            link: res.content.link,
            link_name: res.content.link_name,
            img: res.content.img,
            big_type_id: res.content.big_type_id,
            sort: res.content.sort,
            skip_way: res.content.skip_way,
            intro: res.content.intro,
            id: res.content.id,
          };
        }
      } catch (err) {
        this.errorHandler(err);
      }
    },
    // fromData数据处理
    async btn_submit(e) {
      this.postList(e);
    },
    // 修改请求
    async postList(e) {

      try {
        let res = await this.request({
          url: "/admin/banner/change",
          method: "post",
          loading: true,
          data: {
            name: e.name,
            link: e.link,
            img: e.img,
            big_type_id: e.big_type_id,
            sort: e.sort,
            skip_way: e.skip_way,
            intro: e.intro,
            id: e.id,
          },
        });
        if (res) {
          let that = this;
          this.$message.success({ message: "修改成功", offset: 500 });
          setTimeout(() => {
            // this.$router.go(-1)
            that.pageTurnParams("PublicBanner", { action: "refresh" });
          }, 2000);
        }
      } catch (err) {
        this.errorHandler(err);
      }
    },
  },
};
</script>
<style lang="scss" scoped></style>
